const memory = @import("memory.zig");
const common = @import("common.zig");

pub const Value = f64;

pub const ValueArray = struct {
    count: usize,
    values: ?[]Value,

    pub fn init() ValueArray {
        return ValueArray{
            .count = 0,
            .values = null,
        };
    }

    pub fn write_value_array(self: *ValueArray, value: Value) void {
        if (self.values) |values| {
            if (self.count + 1 > values.len) {
                self.values = memory.grow_array(Value, values, memory.grow_capacity(values.len));
            }
        } else {
            self.values = memory.grow_array(Value, null, 8);
        }

        self.values.?[self.count] = value;
        self.count += 1;
    }

    pub fn deinit(self: *ValueArray) void {
        memory.free_array(self.values.?);
        self.count = 0;
        self.values = null;
    }
};

pub fn print_value(value: Value) !void {
    try common.stdout.print("{e}", .{value});
}
